Skip to content

Route SSE streaming through message broker#3

Open
IanLindsley wants to merge 1 commit intomainfrom
feat/broker-integration
Open

Route SSE streaming through message broker#3
IanLindsley wants to merge 1 commit intomainfrom
feat/broker-integration

Conversation

@IanLindsley
Copy link
Copy Markdown
Collaborator

Summary

  • Replaces the direct engine proxy in the BFF streaming endpoint with the broker's two-step flow: POST to enqueue a message, then GET the SSE stream
  • Adds a TransformStream that translates broker lifecycle events (queued, processing, done, error) into the existing client SSE format
  • Zero browser-side changes — the BFF translates everything so use-chat-runtime.ts receives the same event format as before

Details

  • src/app/api/chat/stream/route.ts — Rewritten to POST to BROKER_BASE_URL/api/v1/message (with X-API-Key auth), then GET BROKER_BASE_URL/api/v1/stream?user_id=X&message_id=Y, piping through a transform that maps broker events to the client's expected status/progress/complete/error format
  • src/types/engine.ts — Added BrokerEnqueueRequest and BrokerEnqueueResponse types
  • wrangler.jsonc — Added BROKER_BASE_URL to vars (BROKER_API_KEY must be set via wrangler secret put)
  • History, preferences, and non-streaming chat still go directly to the engine (unchanged)

Test plan

  • Send a message → verify SSE stream works through broker → verify AI response appears
  • Verify broker lifecycle events (queued, processing, done) are translated correctly
  • Send multiple rapid messages → verify they are processed in order
  • Verify chat history and preferences still work (they bypass the broker)
  • Test error scenarios: broker down, worker timeout
  • Deploy: set BROKER_API_KEY as a Cloudflare secret

Closes #2

🤖 Generated with Claude Code

Replace the direct engine proxy in the BFF streaming endpoint with
the broker's two-step flow: POST to enqueue, GET SSE stream. A
TransformStream translates broker lifecycle events (queued, processing,
done, error) into the existing client SSE format so the browser code
requires no changes.

Closes #2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate with bt-servant-message-broker (SSE streaming)

2 participants